
<!DOCTYPE html>
<html>
<head>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"
          name="viewport"/>
    <meta charset="UTF-8">
    <title>CRM-APP安装包上传与版本更新</title>
	<script>
	    function fileSelected(){
    		var file =document.getElementById('file1').files[0];
    		if(file){
    			var fileSize=0;
    			if(file.size>1024*1024)
    				fileSize=(Math.round(file.size*100/(1024*1024))/100).toString()+'MB';
    			else
    				fileSize=(Math.round(file.size*100/1024)/100).toString()+'KB';
    			document.getElementById('fileName').innerHTML='Name: '+file.name;
    			document.getElementById('fileSize').innerHTML='Size: '+fileSize;
    			document.getElementById('fileType').innerHTML='Type: '+file.type;
    		}
    	}
		function fileSelected2(){
    		var file =document.getElementById('file2').files[0];
    		if(file){
    			var fileSize=0;
    			if(file.size>1024*1024)
    				fileSize=(Math.round(file.size*100/(1024*1024))/100).toString()+'MB';
    			else
    				fileSize=(Math.round(file.size*100/1024)/100).toString()+'KB';
    			document.getElementById('fileName2').innerHTML='Name: '+file.name;
    			document.getElementById('fileSize2').innerHTML='Size: '+fileSize;
    			document.getElementById('fileType2').innerHTML='Type: '+file.type;
    		}
    	}
		
		function upLoadFile(){
			var fd=new FormData();
			fd.append("mfile",document.getElementById('file1').files[0]);
			fd.append("mfile2",document.getElementById('file2').files[0]);
			fd.append("maxVersion",document.getElementById('maxVersion').value);
			fd.append("minVersion",document.getElementById('minVersion').value);
			//fd.append("downloadUrl",document.getElementById('downloadUrl').value);
			fd.append("remark",document.getElementById('remark').value);
			fd.append("appType",document.getElementById('appType').value);
			var xhr = new XMLHttpRequest();
			//xhr.upload.addEventListener("progress",uploadProgress,false);
    		xhr.addEventListener("load",uploadComlpete,false);
    		xhr.addEventListener("error",uploadFailed,false);
    		xhr.addEventListener("abort",uploadCanceled,false);
			xhr.open("POST","http://cxcrmuat.cpic.com.cn/crm-http/crm/uploadAppPackage.do");
			//xhr.open("POST","http://10.191.194.145:9080/crm-http/crm/uploadAppPackage.do");
			xhr.send(fd);
		}
	    function uploadProgress(evt){
    		if(evt.lengthComputable){
    			var percentComplete =Math.round(evt.loaded*100/evt.total);
    			document.getElementById('progressNumber').innerHTML=percentComplete.toString()+'%';
    		}else{
    			document.getElementById('progressNumber').innerHTML='暂无法计算进度';
    		}
    	}
    	function uploadComlpete(evt){
    		alert(evt.target.responseText);
    	}
    	function uploadFailed(evt){
    		alert('上传失败！');
    	}
    	function uploadCanceled(evt){
    		alert('上传文件被取消。。。');
    	}
	</script>
</head>
<body>
<div>
    <input type="file" multiple="multiple" id="ipt">
    <script>
        var oIpt = document.getElementById("ipt");
        oIpt.onchange = function changeFun(){
            // console.log(oIpt.files);
            var files = oIpt.files[0];
            var fd=new FormData();
            fd.append("ipt",files);
            var xhr = createXHR();
            xhr.open("POST","http://cxcrmuat.cpic.com.cn/crm-http/crm/uploadAppPackage.do");
            xhr.onreadstatechange = function(){
                if(xhr.readyState == 4 && xhr.status == 200){

                }
            }
            xhr.onload = function(){console.log("success")};
            xhr.onerror = function(){console.log("error")};
            // xhr.upload.onloadstart = function(){console.log("onloadstart")};
            xhr.upload.onprogress = function(){console.log("onprogress")};
            xhr.send(fd);
        }
    
    </script>

	<form action="http://cxcrmuat.cpic.com.cn/crm-http/crm/uploadAppPackage.do" method="post" enctype="multipart/form-data">
		app类型（1-ios，2-android）<input type="text" name="appType" id="appType" /><br>
		选择上传文件(apk/ipa)<input type="file" name="mfile" id="file1" onchange="fileSelected();"/><br>
		<div id="fileName"></div>
		<div id="fileSize"></div>
		<div id="fileType"></div>
		选择上传文件(plist)<input type="file" name="mfile2"  id="file2" onchange="fileSelected2();"/><br>
		<div id="fileName2"></div>
		<div id="fileSize2"></div>
		<div id="fileType2"></div>
		最大版本<input type="text" name="maxVersion" id="maxVersion" /><br>
		最小版本<input type="text" name="minVersion" id="minVersion" /><br>
		<!--指定下载地址（可为空）<input type="text" name="downloadUrl" id="downloadUrl" /><br>-->
		版本备注<textarea name="remark" id="remark"></textarea><br> 
		<input type="button" value="上传安装包" onclick="upLoadFile()"/>
		<div id="progressNumber"></div>
	</form>
</div>
</body>
</html>




